<template>
	<view class="story-item" :class="{readed: readHistory.find(o=> o===story.id)}" @click="navToDetail(story.id)">
		<view class="text">
			<view class="title">{{story.title}}</view>
			<view class="hint">{{story.hint || story.display_date}}</view>
		</view>
		<image :lazy-load="true" class="thumb" :src="story.images[0]" mode="widthFix"></image>
	</view>
</template>

<script>
	export default {
		name: "StoryItem",
		props: ['story'],
		data() {
			return {
				// 初次进入获取 历史阅读
				readHistory: uni.getStorageSync('zhrb_ReadHistory') || []
			};
		},
		methods: {
			navToDetail: function(storyid) {
				// 保存阅读历史记录
				// console.log(uni.getStorageSync('zhrb_ReadHistory') || [], storyid);
				// const old = uni.getStorageSync('zhrb_ReadHistory') || []
				// old.push(storyid)
				// uni.setStorageSync('zhrb_ReadHistory', old)

				this.readHistory = [storyid, ...this.readHistory]
				uni.setStorageSync('zhrb_ReadHistory', this.readHistory)
        				// 跳转页面
				uni.navigateTo({
					url: "../../pages/detail/detail?id=" + storyid
				})
			}
		}
	}
</script>

<style lang="less">
	.story-item {
		display: flex;
		align-items: center;
		margin: 30rpx;

		&.readed {
			color: #aaaaaa;
		}

		.text {
			flex: 1;

			.title {
				font-size: 30rpx;
				font-weight: bold;
			}

			.hint {
				font-size: 20rpx;
				color: #aaaaaa;
				line-height: 3em;
			}
		}

		.thumb {
			width: 120rpx;
			height: 120rpx;
			border-radius: 6rpx;

		}
	}
</style>
